import 'dart:async';

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 忘记密码
///
///
class PasswordForget extends StatefulWidget {
  const PasswordForget({Key? key}) : super(key: key);

  @override
  State<PasswordForget> createState() => _PasswordForgetState();
}

class _PasswordForgetState extends State<PasswordForget> {

  int timeout = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorsUtils.rgba(245, 245, 245),
      appBar: BrnAppBar(
        backgroundColor: ColorsUtils.rgba(255, 110, 83, 1),
        title: Text('重置密码', style: StylesUtils.customTextStyle(fontSize: Sizes.default18)),
        elevation: 0,
        titleAlignment: Alignment.center,
        themeData: BrnAppBarConfig(
          iconSize: Sizes.default20,
          leadIconBuilder: () {
            return ToolsUtils.getAssetImageIcon('back.png');
          },
          leftAndRightPadding: Sizes.default10,
          titlePadding: EdgeInsets.zero,
        ),
      ),
      body: SingleChildScrollView(
        child: Container(
          decoration: const BoxDecoration(color: Colors.white),
          margin: const EdgeInsets.only(bottom: Sizes.default30),
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default20),
          child: Column(
            children: [
              Container(
                margin: const EdgeInsets.only(top: Sizes.default20),
                alignment: Alignment.centerLeft,
                child: Text('重置密码',
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.color363, fontSize: Sizes.default30)),
              ),
              Container(
                alignment: Alignment.centerLeft,
                child: Text.rich(TextSpan(
                    style: StylesUtils.customTextStyle(
                        color: ColorsUtils.color999, fontSize: Sizes.default13),
                  children: [
                    const TextSpan(
                      text: '请输入 '
                    ),
                    TextSpan(
                      text: '+86136*****678',
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color000)
                    ),
                   const TextSpan(text: '收到的短信验证码，以完成身份验证~')
                  ]
                )
                ),
              ),
              Container(
                margin: const EdgeInsets.only(top: Sizes.default20),
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Expanded(
                        child: Container(
                      margin: const EdgeInsets.only(right: Sizes.default10),
                      child: TextField(
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default16),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: ColorsUtils.rgba(255, 255, 255),
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: 40),
                            hintText: '请输入验证码',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default15, color: ColorsUtils.colorCcc)),
                        keyboardType: TextInputType.text,
                        onChanged: (String content) {},
                      ),
                    )),
                    InkWell(
                      onTap: () {
                        if (timeout == 0) {
                          timeout = 59;
                          Timer.periodic(const Duration(seconds: 1), (Timer timer) {
                            setState(() {
                              if (timeout == 1) {
                                timeout = 0;
                                timer.cancel();
                              } else {
                                timeout--;
                              }
                            });
                          });
                        }
                      },
                      child: Container(
                        constraints: BoxConstraints.tight(const Size(120, Sizes.default40)),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            border: Border.all(color: ColorsUtils.rgba(255, 110, 83, 1)),
                            borderRadius: const BorderRadius.all(Radius.circular(20))),
                        child: Text(
                          timeout == 0 ? '获取验证码' : '${timeout}s',
                          textAlign: TextAlign.center,
                          style: StylesUtils.customTextStyle(color: ColorsUtils.colorFf6),
                        ),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                width: double.maxFinite,
                margin: const EdgeInsets.only(top: Sizes.default30, bottom: Sizes.default40),
                child: GFButton(
                    onPressed: () {
                      Get.toNamed(RouteGet.userPasswordNew);
                    },
                    text: '下一步',
                    textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                    shape: GFButtonShape.pills,
                    type: GFButtonType.solid,
                    size: GFSize.LARGE,
                    color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
